package bb.lanxing.net.utils;

import java.util.Map;
import okhttp3.HttpUrl;

public final class HttpUtils {
    public static String buildUrl(String baseUrl, int port, String path, Map<String, String> params) {
        HttpUrl.Builder newBuilder = HttpUrl.parse(baseUrl).newBuilder();
        if (port > 0) {
            newBuilder.port(port);
        }
        if (path != null) {
            newBuilder.addPathSegments(path);
        }
        if (params != null) {
            for (Map.Entry<String, String> entry : params.entrySet()) {
                newBuilder.addQueryParameter(entry.getKey(), entry.getValue());
            }
        }
        return newBuilder.build().toString();
    }
}
